package cn.rumoss.thread;

/**
 * @ClassName ThreadNumDemo
 * @Description //TODO
 * @Author HeCG
 * @Date 19-4-8 上午9:58
 */
public class ThreadNumDemo {

    public static void main(String[] args) {

        /*ThreadMXBean threadMXBean =ManagementFactory.getThreadMXBean();
        ThreadInfo[] threadInfos=threadMXBean.dumpAllThreads(false,false);
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.println(threadInfo.getThreadId()+"-"+threadInfo.getThreadName());
        }*/
        System.out.println("hello world");
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        ThreadGroup topGroup = group;
        while (group != null) {
            topGroup = group;
            group = group.getParent();
        }
        int nowThreads = topGroup.activeCount();
        Thread[] lstThreads = new Thread[nowThreads];
        topGroup.enumerate(lstThreads);
        for (int i = 0; i < nowThreads; i++) {
            System.out.println("线程number:" + i + " = " + lstThreads[i].getName());
        }

    }

}
